# -*- coding: utf-8 -*-
# @Time : 2024/8/25 15:56
# @Author  : lining
# @FileName: Handle_upload.py
# @Description:上传视频，图片
from Core.elementOpt import Element
from Handle.handle_log import log


def upload(page, loc, file):
    """
    :param page:
    :param loc: 定位方式，点击弹出文件选择框的元素
    :param file: 要上传的文件路径
    :return:
    """
    ele = Element(page)
    try:
        # 点击上传文件按钮，打开文件选框
        with page.expect_file_chooser() as fc_info:
             ele.element_click(loc)
        # 文件选择器
        file_chooser = fc_info.value
        # 上传文件
        file_chooser.set_files(file)
        log.log_info('上传文件成功')
    except Exception as e:
        log.log_error('上传文件失败'+repr(e))
        raise e

